//
//  BVRootViewController.m
//  BuyVegetables1
//
//  Created by pinkfloyd on 16/3/22.
//  Copyright © 2016年 叶思超. All rights reserved.
//

#import "BVRootViewController.h"
#import "MBProgressHUD+MJ.h"
#import "MBProgressHUD.h"
#import "BVHomeViewController.h"
#import "DDMenuController.h"
#import "AppDelegate.h"
#import "BVConst.h"
@interface BVRootViewController ()

@end

@implementation BVRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置导航栏
    [self setupNav];
    // 设置背景图
    [self setupBg];
}

- (void)setupNav {
    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(backClick)];
    self.navigationController.navigationBar.barTintColor = BVBaseOrangeColor;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
}

- (void)backClick{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -- 设置背景图片
- (void)setupBg {
    UIImageView *bgImage = [[UIImageView alloc] init];
    bgImage.frame = self.view.bounds;
    bgImage.userInteractionEnabled = YES;
    bgImage.image = [UIImage imageNamed:@""];
    [self.view addSubview:bgImage];
    self.view.backgroundColor = BVBackgroundLightGrayColor;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    DDMenuController *menuController = (DDMenuController*)((AppDelegate*)[[UIApplication sharedApplication] delegate]).menuController;
    if (![self isMemberOfClass:[BVHomeViewController class]]) {
        menuController.isSleepLeft = YES;
    }else{
        menuController.isSleepLeft = NO;
    }
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [MBProgressHUD hideHUD];
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}

- (void)showMessage:(NSString *)text {
    if (self.view.window) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
        hud.mode = MBProgressHUDModeText;
        if (text == nil || [text isEqualToString:@""]) {
            hud.labelText = @"网络连接似乎出了点异常";
        } else {
            hud.labelText = text;
        }
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:0.8f];
    }
}


@end
